import express from "express";
import { formatRequestQuery, formatResponse } from "../../utils/tools";
import { SysUserService } from "../../services/system/SysRoleService";
const router = express.Router();

router.post("/", async (req, res) => {
  await SysUserService.add(req.body);
  res.send(formatResponse<null>(null, "操作成功"));
});

router.delete("/:id", async (req, res) => {
  const result = await SysUserService.delete(req.params.id);

  res.send(formatResponse(result));
});

router.put("/", async (req, res) => {
  const result = await SysUserService.update(req.body);
  res.send(formatResponse(result));
});

router.get("/page", async (req, res) => {
  const { query, other } = formatRequestQuery(req.query, ["userName"]);
  const result = await SysUserService.findByPage(query.current, query.size, other);
  res.send(formatResponse<typeof result>(result));
});

router.get("/list", async (req, res) => {
  const { other } = formatRequestQuery(req.query, ["userName"]);
  const result = await SysUserService.findByList(other);
  res.send(formatResponse<typeof result>(result));
});

router.get("/:id", async (req, res) => {
  const result = await SysUserService.findById(req.params.id);
  res.send(formatResponse(result));
});

export default router;
